package com.shenmazong.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shenmazong.pojo.TbBrand;
import com.shenmazong.service.TbBrandService;
import com.shenmazong.mapper.TbBrandMapper;
import com.shenmazong.utils.ResultResponse;
import com.shenmazong.vo.BrandInfoVo;
import com.shenmazong.vo.PageVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

/**
 *
 */
@Service
public class TbBrandServiceImpl extends ServiceImpl<TbBrandMapper, TbBrand>
    implements TbBrandService{

    @Autowired
    TbBrandMapper tbBrandMapper;

    @Override
    public ResultResponse getListByPage(PageVo pageVo) {

        Page<TbBrand> page = new Page<>(pageVo.getPageNum(), pageVo.getPageSize());
        Page<TbBrand> tbBrandPage = tbBrandMapper.selectPage(page, null);

        ArrayList<BrandInfoVo> brandInfoVos = new ArrayList<>();
        tbBrandPage.getRecords().forEach(brand -> {
            BrandInfoVo brandInfoVo = new BrandInfoVo();
            BeanUtils.copyProperties(brand, brandInfoVo);

            brandInfoVos.add(brandInfoVo);
        });

        Page<BrandInfoVo> brandInfoVoPage = new Page<BrandInfoVo>();
        BeanUtils.copyProperties(tbBrandPage, brandInfoVoPage);
        brandInfoVoPage.setRecords(brandInfoVos);

        return ResultResponse.SUCCESS(brandInfoVoPage);
    }
}




